#!/bin/bash

############################################################################
#
# 远程执行该脚本，请在命令行中直接执行以下命令：
#
#   curl -sSL https://gitee.com/tay3223/biubiubiu/raw/master/centos7-install-php81-pdns-poweradmin.sh | /bin/bash
#
#
############################################################################

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

yum install -y epel-release

yum install -y nginx

#这个有时会不行，换用下面这种的
#yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
#yum-config-manager --enable remi-php81
#yum install -y php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-intl



mkdir -p "${HOME}"/bao
wget -P "${HOME}"/bao/  http://file.ttpai.work/d/tar/php/php-8.1.x-04-rpm.tar.gz
tar -zxvf "${HOME}"/bao/php-8.1.x-04-rpm.tar.gz -C "${HOME}"/bao/
yum install -y "${HOME}"/bao/php-8.1/*

php -v

cat > /etc/nginx/conf.d/poweradmin.conf <<\EOF
server {
    listen       80;
    server_name  localhost;
    root         /var/www/poweradmin;


    location / {
      index index.php index.html index.htm;
    }


    location ~ .php$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }

}
EOF


# 启动nginx
systemctl restart nginx
systemctl status nginx
systemctl enable nginx


# 修改php.ini配置
sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf
sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf


# 授权
chown -R nginx. /var/lib/php/


# 启动PHP服务
systemctl restart php-fpm.service
systemctl status php-fpm.service
systemctl enable php-fpm.service


mkdir -p "${HOME}"/bao
wget -P "${HOME}"/bao/ http://file.ttpai.work/d/tar/pdns/poweradmin-2.2.2.tar.gz


tar -zxvf "${HOME}"/bao/poweradmin-2.2.2.tar.gz -C "${HOME}"/bao/


mkdir -p /var/www/poweradmin && rm -rf /var/www/poweradmin/*


mv "${HOME}"/bao/poweradmin-2.2.2/*  /var/www/poweradmin/


chown -R nginx. /var/www/poweradmin/


#获取本机IP地址
local_ip=`ip address show | awk '/inet / {print $2}' | grep -v 127.0.0.1 | cut -d'/' -f1`


cat <<Tay

====================================
剩下的步骤在浏览器执行安装操作
====================================

    http://${local_ip}/install/


Tay
